import * as actionTypes from '../constants/home';
import axios from 'axios';
import {fromJS} from "immutable";

const getTpcList = (data) => ({
    type: actionTypes.GET_TOPIC_LIST,
    data: fromJS(data)
});

const getAtcList = (data) => ({
    type: actionTypes.GET_ARTICLE_LIST,
    data: fromJS(data)
});

const getRmdList = (data) => ({
    type: actionTypes.GET_RECOMMEND_LIST,
    data: fromJS(data)
});

export const getTopicList = () => {
    return (dispatch) => {
        axios.get('/api/homeTopicList.json').then(res => {
            let data = res.data;
            dispatch(getTpcList(data.data));
        }).catch(() => {

        })
    }
};

export const getArticleList = () => {
    return (dispatch) => {
        axios.get('/api/homeArticleList.json').then(res => {
            let data = res.data;
            dispatch(getAtcList(data.data));
        }).catch(() => {

        })
    }
};

export const getRecommendList = () => {
    return (dispatch) => {
        axios.get('/api/homeRecommendList.json').then(res => {
            let data = res.data;
            dispatch(getRmdList(data.data));
        }).catch(() => {

        })
    }
};

export const getMoreList = () => {
    return (dispatch) => {
        console.log('clicked & loadMore');
        // axios.get('').then(res => {
        //
        // }).catch(() => {
        //
        // })
    }
};

export const changeBackToTopShow = (show) => ({
    type : actionTypes.CHANGE_BACKTOTOP_SHOW,
    isShow : show
});